package com.wuyou.simple;

import cn.hutool.core.date.DateUtil;

import java.util.*;

/**
 * 1704. 判断字符串的两半是否相似
 */
public class HalvesAreAlike {

    public static void main(String[] args) {
//        System.out.println((int) 'A');
//        System.out.println('a' - 'A');
//        String s = "MerryChristmas";
//        System.out.println(solution_3(s));

        System.out.println(DateUtil.beginOfWeek(new Date()));
        System.out.println(DateUtil.endOfWeek(new Date()));

        Random random = new Random();
        System.out.println(random.nextDouble() * 100);
    }

    // 同学代码 很厉害
    public static boolean solution_4(String s) {
        char[] chars = s.toCharArray();
        int[] cs = new int['z' + 1];
//        for (int i = 0, half = s.length() >> 1, j = half; i < half; cs[chars[i]]++, cs[chars[j]]--, i++,j++) {
        for (int i = 0, half = s.length() >> 1, j = half; i < half; i++, j++) {
            cs[chars[i]] ++;
            cs[chars[j]] --;
        }
        return cs['a'] + cs['e'] + cs['i'] + cs['o'] + cs['u'] + cs['A'] + cs['e'] + cs['I'] + cs['O'] + cs['U'] == 0;
    }

    // 2ms 内存消耗少
    public static boolean solution_3(String s) {
        int left = 0, right = s.length() - 1, count = 0;
        Character[] c = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
        byte[] b = new byte['z' + 1];
        for (int i = 0; i < c.length; i++) {
            b[c[i] - 'A'] = 1;
        }
        char[] chars = s.toCharArray(); // 数组比String.charAt()更快 内存消耗更少  1ms
        while (left < right) {
            if (b[chars[left] - 'A'] == 1) count++;
            if (b[chars[right] - 'A'] == 1) count--;
            left++;
            right--;
        }
        return count == 0;
    }

    // 速度一样 内存消耗严重
    public boolean solution_2(String s) {
        Map<Character, Integer> map = new HashMap<>();
        map.put('a', 0);
        map.put('e', 0);
        map.put('i', 0);
        map.put('o', 0);
        map.put('u', 0);
        map.put('A', 0);
        map.put('E', 0);
        map.put('I', 0);
        map.put('O', 0);
        map.put('U', 0);
        int left = 0, right = s.length() - 1, count = 0;
        while (left < right) {
            if (map.get(s.charAt(left)) != null) count++;
            if (map.get(s.charAt(left)) != null) count--;

            left++;
            right--;
        }
        return count == 0;
    }

    // 5ms
    public boolean solution_1(String s) {
        Character[] c = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
        List<Character> list = Arrays.asList(c);
        int left = 0, right = s.length() - 1, count = 0;
        while (left < right) {
            if (list.contains(s.charAt(left))) count++;
            if (list.contains(s.charAt(right))) count--;

            left++;
            right--;
        }
        return count == 0;
    }
}
